package battleship;

/**
 *
 * @author Tomek
 */
public class Coords implements Comparable<Coords> {

	private boolean hit = false;
	Integer x, y;
	Ship owner;

	public Coords(int x, int y, Ship parent) {
		this.x = x;
		this.y = y;
		this.owner = parent;
	}

	public boolean isHit() {
		return hit;
	}

	public void hit() {
		hit = true;
	}

	@Override
	public boolean equals(Object o) {
		if (o == null) {
			return false;
		}
		Coords d;

		if (o instanceof Coords) {
			d = (Coords) (o);
		} else {
			return false;
		}

		if (x == d.x && y == d.y) {
			return true;
		}

		return false;
	}

	@Override
	public int hashCode() {
		return 23 * x + y;
	}

	@Override
	public int compareTo(Coords o) {
		if (x != o.x) {
			return x.compareTo(o.x);
		}
		return y.compareTo(o.y);
	}

	@Override
	public String toString() {
		return "" + ((char) ('A' + y)) + (x+1);
	}
}
